package com.zfp.hs.controller;

import com.zfp.core.controller.BaseController;
import com.zfp.core.plugins.page.Page;
import com.zfp.hs.entity.Timeline;
import com.zfp.hs.service.TimelineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.PrintWriter;

@Controller
@RequestMapping("hs/timeline/")
public class TimelineController extends BaseController {
	@Autowired
	private TimelineService timelineService;

	@RequestMapping("timelinelist")
	public String timelinelist(Timeline timeline, Model model, Page<Timeline> page){
		if (page.getShowCount() == 20) {
			page.setShowCount(13); // 初始页面每页几行自定义
		}
		page=timelineService.pageList(page, timeline);
		model.addAttribute("page",page);
		model.addAttribute("timeline",timeline);
		return "hs/timelinelist";

	}
	@RequestMapping("turnSave")
	public String turn(Timeline timeline,Model model){
		if(timeline.getId() != null){
			Timeline timelineupdate=timelineService.getById("Timeline.getById", timeline.getId().toString());
			model.addAttribute("timelineupdate",timelineupdate);
		}
		model.addAttribute("timelime",timeline);
		return "hs/timelineSavePage";
	}
	@RequestMapping("save")
	public void save(PrintWriter out, Timeline timeline){
		//System.out.println(sysUser.getUserId());
		Boolean b = timelineService.save(timeline);
		//System.out.println(b);
		out.print(b);
		out.close();
	}
	@RequestMapping("delete")
	public void delete(PrintWriter out,Timeline Timeline){

		Boolean b = timelineService.deleteById(Timeline);
		out.print(b);
		out.close();
	}
}